﻿package frEngine.animateControler.particleControler
{
    import __AS3__.vec.*;
    import flash.geom.*;
    import frEngine.math.*;
    import frEngine.util.*;

    public class PEmitterDirectionInfo extends Object
    {
        public var motionType:int = 0;
        public var isRandom:Boolean = true;
        public var direction_vector_x:Number = 0;
        public var direction_vector_y:Number = 0;
        public var direction_vector_z:Number = 0;
        public var directionVariation:Number = 0;
        public var direction_radian:Number = 0;
        public var direction_rotateX:Number = 0;
        public var direction_rotateY:Number = 0;
        public var direction_rotateZ:Number = 0;
        private var direction_rotate_offset:Number = 0;
        public var herizonAngle:Number = 0;
        private var randnomArr0:Array;
        private var randnomArr1:Array;
        private var randnomArr2:Array;
        private var randnomArr3:Array;

        public function PEmitterDirectionInfo(param1:Object)
        {
            this.isRandom = param1.isRandom;
            this.motionType = param1.motionType;
            this.direction_vector_x = param1.direction_vector_x;
            this.direction_vector_y = param1.direction_vector_y;
            this.direction_vector_z = param1.direction_vector_z;
            this.direction_radian = param1.direction_radian / 180 * Math.PI;
            this.direction_rotate_offset = (-this.direction_radian) / 2;
            this.direction_rotateX = param1.direction_rotateX / 180 * Math.PI;
            this.direction_rotateY = param1.direction_rotateY / 180 * Math.PI;
            this.direction_rotateZ = param1.direction_rotateZ / 180 * Math.PI;
            this.directionVariation = param1.directionVariation;
            this.herizonAngle = param1.herizonAngle;
            return;
        }// end function

        public function dispose() : void
        {
            this.randnomArr0 = null;
            this.randnomArr1 = null;
            this.randnomArr2 = null;
            this.randnomArr3 = null;
            return;
        }// end function

        public function init(param1:uint, param2:uint, param3:uint) : void
        {
            this.randnomArr0 = HelpUtils.getRandomArr(param2, param1, param3);
            this.randnomArr1 = HelpUtils.getRandomArr(param2, param1, param3 + 100);
            this.randnomArr2 = HelpUtils.getRandomArr(param2, param1, param3 + 200);
            this.randnomArr3 = HelpUtils.getRandomArr(param2, param1, param3 + 300);
            return;
        }// end function

        private function createType4(param1:uint, param2:Number, param3:Number, param4:Vector.<Number>, param5:Number, param6:Number, param7:Vector.<Number>, param8:int) : void
        {
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Number = NaN;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_18:int = 0;
            var _loc_14:* = new Vector3D();
            var _loc_17:int = 0;
            while (_loc_17 < param1)
            {
                
                _loc_9 = 0;
                while (_loc_9 < param2)
                {
                    
                    _loc_16 = this.randnomArr0[_loc_9];
                    _loc_15 = param6 + param5 * _loc_16;
                    _loc_18 = _loc_9 * param3 * 3;
                    _loc_14.x = param8 * param7[_loc_18];
                    _loc_14.y = param8 * param7[(_loc_18 + 1)];
                    _loc_14.z = param8 * param7[_loc_18 + 2];
                    _loc_14.normalize();
                    _loc_11 = _loc_14.x * _loc_15;
                    _loc_12 = _loc_14.y * _loc_15;
                    _loc_13 = _loc_14.z * _loc_15;
                    _loc_10 = 0;
                    while (_loc_10 < param3)
                    {
                        
                        param4.push(_loc_11, _loc_12, _loc_13);
                        _loc_10++;
                    }
                    _loc_9++;
                }
                _loc_17++;
            }
            return;
        }// end function

        private function createType3(param1:uint, param2:Number, param3:Number, param4:Vector.<Number>, param5:Number, param6:Number) : void
        {
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_12:* = new Vector3D();
            var _loc_14:* = new Vector3D(this.direction_vector_x, this.direction_vector_y, this.direction_vector_z);
            _loc_14.normalize();
            _loc_14.scaleBy(1 - this.directionVariation);
            var _loc_15:int = 0;
            while (_loc_15 < param1)
            {
                
                _loc_7 = 0;
                while (_loc_7 < param2)
                {
                    
                    _loc_13 = param6 + param5 * this.randnomArr3[_loc_7];
                    _loc_12.x = 0.5 - this.randnomArr0[_loc_7];
                    _loc_12.y = 0.5 - this.randnomArr1[_loc_7];
                    _loc_12.z = 0.5 - this.randnomArr2[_loc_7];
                    _loc_12.normalize();
                    _loc_12.scaleBy(this.directionVariation);
                    _loc_12 = _loc_12.add(_loc_14);
                    _loc_12.normalize();
                    _loc_12.scaleBy(_loc_13);
                    _loc_9 = _loc_12.x;
                    _loc_10 = _loc_12.y;
                    _loc_11 = _loc_12.z;
                    _loc_8 = 0;
                    while (_loc_8 < param3)
                    {
                        
                        param4.push(_loc_9, _loc_10, _loc_11);
                        _loc_8++;
                    }
                    _loc_7++;
                }
                _loc_15++;
            }
            return;
        }// end function

        public function setDirectionVector(param1:uint, param2:Number, param3:Number, param4:Number, param5:Vector.<Number>, param6:int, param7:Vector.<Number>) : void
        {
            var _loc_8:* = param3 * param4;
            var _loc_9:* = param4 - _loc_8;
            var _loc_10:* = _loc_8 * 2;
            switch(this.motionType)
            {
                case 1:
                {
                    this.createType1(param1, param2, param6, param5, _loc_10, _loc_9);
                    break;
                }
                case 2:
                {
                    this.createType2(param1, param2, param6, param5, _loc_10, _loc_9);
                    break;
                }
                case 3:
                {
                    this.createType3(param1, param2, param6, param5, _loc_10, _loc_9);
                    break;
                }
                case 4:
                {
                    this.createType4(param1, param2, param6, param5, _loc_10, _loc_9, param7, -1);
                    break;
                }
                case 5:
                {
                    this.createType4(param1, param2, param6, param5, _loc_10, _loc_9, param7, 1);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function createType2(param1:uint, param2:Number, param3:Number, param4:Vector.<Number>, param5:Number, param6:Number) : void
        {
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_17:Quaternion = null;
            var _loc_19:Number = NaN;
            var _loc_20:Number = NaN;
            var _loc_21:Number = NaN;
            var _loc_12:* = new Vector3D();
            var _loc_14:* = this.direction_radian / param2;
            if (this.direction_rotateX != 0 || this.direction_rotateY != 0 || this.direction_rotateZ != 0)
            {
                _loc_17 = this.createQuaternion();
            }
            var _loc_18:int = 0;
            while (_loc_18 < param1)
            {
                
                _loc_16 = this.randnomArr0[_loc_18];
                _loc_19 = 0;
                _loc_7 = 0;
                while (_loc_7 < param2)
                {
                    
                    _loc_16 = this.randnomArr0[_loc_7];
                    _loc_20 = (1 - _loc_16 * 2) * this.herizonAngle;
                    _loc_12.y = Math.sin(_loc_20);
                    _loc_21 = Math.cos(this.herizonAngle);
                    if (this.isRandom)
                    {
                        _loc_16 = this.randnomArr1[_loc_7];
                        _loc_15 = _loc_16 * this.direction_radian + this.direction_rotate_offset;
                        _loc_12.z = _loc_21 * Math.cos(_loc_15);
                        _loc_12.x = _loc_21 * Math.sin(_loc_15);
                    }
                    else
                    {
                        _loc_15 = _loc_7 * _loc_14 + _loc_19 + this.direction_rotate_offset;
                        _loc_12.z = _loc_21 * Math.cos(_loc_15);
                        _loc_12.x = _loc_21 * Math.sin(_loc_15);
                    }
                    _loc_16 = this.randnomArr2[_loc_7];
                    _loc_13 = param6 + param5 * _loc_16;
                    _loc_9 = _loc_12.x * _loc_13;
                    _loc_10 = _loc_12.y * _loc_13;
                    _loc_11 = _loc_12.z * _loc_13;
                    _loc_8 = 0;
                    while (_loc_8 < param3)
                    {
                        
                        param4.push(_loc_9, _loc_10, _loc_11);
                        _loc_8++;
                    }
                    _loc_7++;
                }
                _loc_18++;
            }
            return;
        }// end function

        private function createType1(param1:uint, param2:Number, param3:Number, param4:Vector.<Number>, param5:Number, param6:Number) : void
        {
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_14:Number = NaN;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_17:Number = NaN;
            var _loc_12:* = new Vector3D();
            var _loc_18:int = 0;
            while (_loc_18 < param1)
            {
                
                _loc_7 = 0;
                while (_loc_7 < param2)
                {
                    
                    _loc_14 = this.randnomArr0[_loc_7];
                    _loc_15 = this.randnomArr1[_loc_7];
                    _loc_16 = this.randnomArr2[_loc_7];
                    _loc_17 = this.randnomArr3[_loc_7];
                    _loc_13 = param6 + param5 * _loc_17;
                    _loc_12.x = 0.5 - _loc_14;
                    _loc_12.y = 0.5 - _loc_15;
                    _loc_12.z = 0.5 - _loc_16;
                    _loc_12.normalize();
                    _loc_9 = _loc_12.x * _loc_13;
                    _loc_10 = _loc_12.y * _loc_13;
                    _loc_11 = _loc_12.z * _loc_13;
                    _loc_8 = 0;
                    while (_loc_8 < param3)
                    {
                        
                        param4.push(_loc_9, _loc_10, _loc_11);
                        _loc_8++;
                    }
                    _loc_7++;
                }
                _loc_18++;
            }
            return;
        }// end function

        private function createQuaternion() : Quaternion
        {
            var _loc_1:Vector3D = null;
            var _loc_2:* = new Quaternion();
            _loc_2.fromEulerAngles(this.direction_rotateY, this.direction_rotateZ, this.direction_rotateX);
            return _loc_2;
        }// end function

    }
}
